﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace loginWeb
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        
            
       protected void btnLogin_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112109;uid=2014112109;pwd=19950627";
            SqlConnection cn = new SqlConnection(strCn);
            if (this.RadioButton1.Checked == true)
            {
                try
                {
                    string 登录名 = this.txtUsername.Text.ToString();
                    string 密码 = this.txtPwd.Text.ToString();
                    cn.Open();
                    string strSql = "SELECT   登录名, 密码 ,头像,邮箱 FROM      Users1  WHERE   (登录名 = N'" + txtUsername.Text + "') AND (密码 = N'" + txtPwd.Text + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        登录名 = "SELECT   登录名  FROM     Users1";
                        密码 = "SELECT   密码  FROM      Users1";
                        string picture = Request.QueryString["头像"];
                        string Qq = Request.QueryString["邮箱"];
                        string name = Request.QueryString["登录名"];


                        {

                            Session["picture"] = "~\\头像\\" + dr["头像"].ToString() + ".jpg";
                            Session["Qq"] = dr["邮箱"].ToString();
                            Session["name"] = dr["登录名"].ToString();
                            Session["password"] = dr["密码"].ToString();
                            Response.Redirect("WebForm2.aspx");

                        }


                    }
                    else
                    {
                        Response.Write("<script>alert('您填写的登录信息有误，请重新填写。');location.href='Index.aspx';</script>");
                    }
                }
                catch (Exception ex)
                {
                    this.lblInfo.Text = ex.Message;
                }
                finally
                {
                    cn.Close();
                }
            }
           else if (this.RadioButton2.Checked == true)
            {
                try
                {
                    string 登录名 = this.txtUsername.Text.ToString();
                    string 密码 = this.txtPwd.Text.ToString();
                    cn.Open();
                    string strSql = "SELECT   登录名,密码  FROM     Admin  WHERE   (登录名= N'" + txtUsername.Text + "') AND (密码 = N'" + txtPwd.Text + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {

                        登录名 = "SELECT   登录名  FROM     Admin";
                        密码 = "SELECT   密码  FROM      Admin";
                         {
                             Session["name"] = dr["登录名"].ToString();
                             Session["password"] = dr["密码"].ToString();

                        
                            Response.Redirect("WebAdmin1.aspx");

                        }
                       
                    }
                    else
                    {
                        Response.Write("<script>alert('您填写的登录信息有误，请重新填写。');location.href='Index.aspx';</script>");
                    }
                }
                catch (Exception ex)
                {
                    this.lblInfo.Text = ex.Message;
                }
                finally
                {
                    cn.Close();
                }
            }
        }

        protected void txtPwd_TextChanged(object sender, EventArgs e)
        {

        }

        protected void btnRe_Click(object sender, EventArgs e)
        {
            this.txtUsername.Text = "  ";
            this.txtPwd.Text = "  ";

        }

        protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}